<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      v-show="showSearch"
      label-width="80px"
    >
      <el-form-item label="工单编码" prop="orderCode">
        <el-input
          v-model="queryParams.orderCode"
          placeholder="请输入工单编码"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="物料名称" prop="materialName">
        <el-input
          v-model="queryParams.materialName"
          placeholder="请输入物料名称"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="产品编码" prop="productCode">
        <el-input
          v-model="queryParams.productCode"
          placeholder="请输入产品编码"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="产线名称" prop="lineName">
        <el-input
          v-model="queryParams.lineName"
          placeholder="请输入产线名称"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划编码" prop="planCode">
        <el-input
          v-model="queryParams.planCode"
          placeholder="请输入计划编码"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="工单状态" prop="orderState">
        <el-select
          v-model="queryParams.orderState"
          placeholder="请选择工单状态"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in orderOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="工艺路线名称" prop="routingName" label-width="100px">
        <el-input
          v-model="queryParams.routingName"
          placeholder="请输入工艺路线名称"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="华为任务令" prop="taskTon" label-width="90px">
        <el-input
          v-model="queryParams.taskTon"
          placeholder="请输入华为任务令"
          clearable
          size="small"
          style="width: 200px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="cyan"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索
        </el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
        >重置
        </el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['function:order:add']"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['function:order:edit']"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['function:order:remove']"
        >删除</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['function:order:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :element-loading-text="loadText"
      :data="orderList"
      @selection-change="handleSelectionChange"
      style="width: 100%"
    >
      <el-table-column
        type="selection"
        width="60"
        align="center"
        fixed="left"
      />
      <el-table-column
        label="工单主键id"
        align="center"
        width="100"
        fixed="left"
        prop="orderId"
        v-if="false"
      />
      <el-table-column
        label="工单编码"
        align="center"
        prop="orderCode"
        width="200"
        fixed="left"
      >
        <template slot-scope="scope">
          <el-button type="text" @click="showDictData(scope.row)">{{
              scope.row.orderCode
            }}
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="工单数量"
        align="center"
        prop="orderNumber"
        width="100"
      />
      <el-table-column
        label="产品编码"
        align="center"
        prop="productCode"
        width="100"
      />
      <el-table-column
        label="产品名称"
        align="center"
        prop="materialName"
        width="200"
      />
      <el-table-column
        label="华为任务令"
        align="center"
        prop="taskTon"
        width="100"
      />
      <el-table-column
        label="计划编码"
        align="center"
        prop="planCode"
        width="200"
      />
      <!-- <el-table-column label="计划数量" align="center" prop="planNumber" width="100" /> -->
      <!-- <el-table-column label="物料名称" align="center" prop="materialName" width="200" /> -->
      <el-table-column
        label="产线编码"
        align="center"
        prop="lineCode"
        width="100"
      />
      <el-table-column
        label="产线名称"
        align="center"
        prop="lineName"
        width="200"
      />
      <el-table-column
        label="工艺路线编码"
        align="center"
        prop="routingCode"
        width="160"
      />
      <el-table-column
        label="工艺路线名称"
        align="center"
        prop="routingName"
        width="200"
      />
      <el-table-column
        label="计划开始时间"
        align="center"
        prop="startTime"
        width="160"
      />
      <el-table-column
        label="计划结束时间"
        align="center"
        prop="endTime"
        width="160"
      />
      <el-table-column
        label="工单状态"
        align="center"
        prop="orderState"
        :formatter="handleStatus"
        width="100"
      />
      <el-table-column label="班组" align="center" prop="team" width="100"/>
      <el-table-column label="备注" align="center" prop="remarks" width="200"/>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="300"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="small"
            type="primary"
            style="margin: 3px"
            @click="handleVerify(scope.row)"
          >版本校验
          </el-button
          >
          <el-button

            size="small"

            style="margin: 3px"
            type="primary"
            :disabled="scope.row.orderState !== '1'|| scope.row.orderState !== '2'"

            @click="handleUpdate(scope.row)"
            v-hasPermi="['function:order:edit']"
          >修改
          </el-button
          >
          <el-button
            size="small"
            type="danger"

            style="margin: 3px"

            :disabled="scope.row.orderState !== '1'"

            @click="handleDelete(scope.row)"
            v-hasPermi="['function:order:remove']"
          >删除
          </el-button
          >
          <el-button
            size="small"
            type="primary"

            style="margin: 3px"

            :disabled="scope.row.orderState !== '1'"

            @click="handleQT(scope.row)"
            v-hasPermi="['function:order:qitao']"
          >齐套验证
          </el-button>
          <el-button

            type="primary"
            size="small"
            style="margin: 3px"
            :disabled="scope.row.orderState == '3'||scope.row.orderState == '4'"
            @click="handleTransmit(scope.row)"
            v-hasPermi="['function:order:transmit']"
          >工单下发
          </el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改工单信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="760px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="20">
          <el-col :lg="12">
            <el-form-item label="工单编码" prop="orderCode">
              <el-input
                v-model="form.orderCode"
                placeholder="请输入工单编码"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="产品名称" prop="productCode">
              <el-select
                v-model="form.productCode"
                placeholder="请选产品名称"
                style="width: 240px"
                disabled
              >
                <el-option
                  v-for="item in productOptions"
                  :key="item.modelCode"
                  :label="item.ledName"
                  :value="item.modelCode"
                >
                  <span style="float: left">{{ item.modelCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                      item.ledName
                    }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="计划编码" prop="planCode">
              <el-input
                v-model="form.planCode"
                placeholder="请输入计划号"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="工单数量" prop="orderNumber">
              <el-input
                v-model="form.orderNumber"
                placeholder="请输入工单数量"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="工单状态" prop="orderState">
              <el-select
                v-model="form.orderState"
                placeholder="请选择工单状态"
                style="width: 240px"
                disabled
              >
                <el-option
                  v-for="item in orderOptions"
                  :key="item.dictValue"
                  :label="item.dictLabel"
                  :value="item.dictValue"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="班组" prop="team">
              <el-input
                v-model="form.team"
                placeholder="请输入班组"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <!-- <el-col :lg="12">
            <el-form-item label="物料名称" prop="materialCode">
              <el-select
                v-model="form.materialCode"
                placeholder="请选择物料名称"
                style="width: 240px"
              >
                <el-option
                  v-for="item in materialOptions"
                  :key="item.materialCode"
                  :label="item.materialName"
                  :value="item.materialCode"
                >
                  <span style="float: left">{{ item.materialCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{ item.materialName }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col> -->
          <el-col :lg="12">
            <el-form-item label="产线名称" prop="lineCode">
              <el-select
                v-model="form.lineCode"
                placeholder="请选产线名称"
                style="width: 240px"
              >
                <el-option
                  v-for="item in lineOptions"
                  :key="item.shopCode"
                  :label="item.shopName"
                  :value="item.shopCode"
                >
                  <span style="float: left">{{ item.shopCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                      item.shopName
                    }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="工艺路线名称" prop="routingCode">
              <el-select
                v-model="form.routingCode"
                placeholder="请选择工艺路线名称"
                style="width: 240px"
              >
                <el-option
                  v-for="item in routingOptions"
                  :key="item.id"
                  :label="item.routingName"
                  :value="item.routingCode"
                >
                  <span style="float: left">{{ item.routingCode }}</span>
                  <span style="float: right; color: #8492a6; font-size: 13px">{{
                      item.routingName
                    }}</span>
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :lg="12">
            <el-form-item label="备注" prop="remarks">
              <el-input
                v-model="form.remarks"
                type="textarea"
                :rows="4"
                placeholder="请输入备注"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="齐套详情"
      :visible.sync="stepsVisible"
      width="80%"
      :lock-scroll="false"
    >
      <qt-Info :orderId="orderId"></qt-Info>
    </el-dialog>
    <!-- 版本校验对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openVerify"
      width="760px"
      append-to-body
    >
      <el-table
        v-loading="loadingVerify"
        :data="entityRevisionList"
        width="760px"
      >
        <el-table-column
          label="组织ID"
          align="center"
          prop="zorgid"
          :show-overflow-tooltip="true"
          width="100"
        />
        <el-table-column
          label="任务令"
          align="center"
          prop="entityName"
          :show-overflow-tooltip="true"
          width="150"
        />
        <!-- <el-table-column label="工单号" align="center" prop="workNumber" width="100" /> -->
        <el-table-column
          label="项目编码"
          align="center"
          prop="itemNumber"
          width="100"
        />
        <el-table-column
          label="项目版本"
          align="center"
          prop="itemVer"
          :show-overflow-tooltip="true"
          width="100"
        />
        <el-table-column
          label="软件编码"
          align="center"
          prop="softItem"
          :show-overflow-tooltip="true"
          width="100"
        />
        <el-table-column
          label="软件名称"
          align="center"
          prop="softName"
          width="120"
        />
        <el-table-column
          label="软件版本"
          align="center"
          prop="revision"
          width="150"
        />
        <el-table-column
          label="软件位置"
          align="center"
          prop="softLocation"
          :show-overflow-tooltip="true"
          width="100"
        />
        <el-table-column
          label="加工方式"
          align="center"
          prop="modeProcduction"
          :show-overflow-tooltip="true"
          width="100"
          :formatter="modeFormatter"

        />
        <el-table-column
          label="是否需要特殊版本"
          align="center"
          prop="specialRevision"
          :formatter="revisionFormatter"

        />
        <el-table-column
          label="软件层级"
          align="center"
          prop="softLevel"
          :show-overflow-tooltip="true"
          width="100"
        />
        <el-table-column
          label="软件版本是否变更"
          align="center"
          prop="existUpdated"
          :show-overflow-tooltip="true"
          width="150"
          :formatter="updatedFormatter"

        />
        <el-table-column
          label="创建人"
          align="center"
          prop="createdby"
          :show-overflow-tooltip="true"
          width="100"
        />
        <el-table-column
          label="创建时间"
          align="center"
          prop="createddate"
          width="100"
        />
        <el-table-column
          label="更新人"
          align="center"
          prop="updatedby"
          width="100"
        />
        <el-table-column
          label="更新时间"
          align="center"
          prop="updatedDate"
          width="100"
        />
        <el-table-column
          label="预留字段"
          align="center"
          prop="segment1"
          width="100"
        />
        <el-table-column
          label="回传的开工时间值，如未回传则为空"
          align="center"
          prop="segment2"
          width="150"
        />
        <el-table-column
          label="回传的回货时间值，如未回传则为空"
          align="center"
          prop="segment3"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="软件编码在BOM里面的父项编码"
          align="center"
          prop="segment4"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="如是烧录软件，该位置为软件的载体编码"
          align="center"
          prop="segment5"
          :show-overflow-tooltip="true"
          width="150"
        />
        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
          width="100"
          fixed="right"
        >
          <template slot-scope="scope">
            <el-button
              size="small"
              type="primary"
              style="margin-right: 9px"
              @click="updateVerify(scope.row)"
              :disabled="flag"
            >

              修改
            </el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
    <el-button @click="openVerify = false">取 消</el-button>
    <el-button v-loading="loadingVerify" type="primary" @click="submitList" :disabled="flag">确 定</el-button>
  </span>
    </el-dialog>
    <!-- 修改版本校验对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="openUpdate"
      width="800px"
      append-to-body
    >
      <el-form
        ref="verifyForm"
        :model="verifyForm"
        :rules="rules"
        label-width="130px"
      >
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="任务令" prop="entityName">
              <el-input
                v-model="verifyForm.entityName"
                placeholder="请输入任务令"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="工单号" prop="workNumber">
              <el-input
                v-model="verifyForm.workNumber"
                placeholder="请输入工单号"
                style="width: 240px"
                disabled
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目编码" prop="itemNumber">
              <el-input
                v-model="verifyForm.itemNumber"
                placeholder="请输入项目编码"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目版本" prop="itemVer">
              <el-input
                v-model="verifyForm.itemVer"
                placeholder="请输入项目版本"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="软件编码" prop="softItem">
              <el-input
                v-model="verifyForm.softItem"
                placeholder="请输入软件编码"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="软件名称" prop="softName">
              <el-input
                v-model="verifyForm.softName"
                placeholder="请输入软件名称"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="软件版本是否变更" prop="updatedRevision">
              <!-- <el-input
                v-model="verifyForm.updatedRevision"
                placeholder="请输入更新的软件版本"
                style="width: 240px"
              /> -->
              <el-select
                v-model="verifyForm.updatedRevision"
                placeholder="请选软件版本是否变更"
                style="width: 240px"
              >
                <el-option
                  v-for="item in updatedRevisionList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="软件位置" prop="softLocation">
              <el-input
                v-model="verifyForm.softLocation"
                placeholder="请输入软件位置"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="加工方式" prop="modeProcduction">

              <el-select
                v-model="verifyForm.modeProcduction"
                placeholder="请选加工方式"
                style="width: 240px"
              >
                <el-option
                  v-for="item in modeProcductionList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否有特殊版本" prop="specialRevision">

              <el-select
                v-model="verifyForm.specialRevision"
                placeholder="请选是否有特殊版本"
                style="width: 240px"
              >
                <el-option
                  v-for="item in specialRevisionList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="软件层级" prop="softLevel">
              <el-input
                v-model="verifyForm.softLevel"
                placeholder="请输入软件层级"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外协厂" prop="vendorId">
              <el-input
                v-model="verifyForm.vendorId"
                placeholder="请输入外协厂"
                style="width: 240px"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitVerifyForm">确 定</el-button>
        <el-button @click="cancelVerify">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listOrder,
  getOrder,
  delOrder,
  transmitOrder,
  qtOrder,
  addOrder,
  updateOrder,
  exportOrder,
  getPoVersion,
  updatePoVersion,
} from "@/api/function/order";
import {listMaterial, listProduct, listOperations} from "@/api/function/prod";
import {getTree} from "@/api/pull/feedSet";
import qtInfo from "@/views/components/qtInfo";

export default {
  name: "Order",
  components: {qtInfo},
  data() {
    return {
      // 遮罩层
      loading: true,
      loadingVerify: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 工单table弹框
      stepsVisible: false,
      // orderId
      orderId: "",
      // 工单信息表格数据
      orderList: [],
      // 工单状态
      orderOptions: [],
      // 物料名称下拉框
      materialOptions: [],
      // 产线名称下拉框
      lineOptions: [],
      // 产品名称下拉框
      productOptions: [],
      // 工艺路线名称下拉框
      routingOptions: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderCode: undefined,
        productName: undefined,
        lineName: undefined,
        planCode: undefined,
        orderState: undefined,
        routingName: undefined,
        taskTon: undefined,
      },
      // 表单参数
      form: {},
      verifyForm: {},
      // 表单校验
      rules: {
        orderCode: [
          {required: true, message: "工单编码不能为空", trigger: "change"},
        ],
        productCode: [
          {required: true, message: "产品名称不能为空", trigger: "change"},
        ],
        planCode: [
          {required: true, message: "计划编码不能为空", trigger: "change"},
        ],
        orderNumber: [
          {required: true, message: "工单数量不能为空", trigger: "change"},
        ],
      },
      openVerify: false,
      entityRevisionList: [],
      openUpdate: false,
      verifyPo: "",
      verifyOrderId: "",
      modeProcductionList: [{value: '0', label: '烧录软件'}, {value: '1', label: '加载软件'}],
      specialRevisionList: [{value: '0', label: '否'}, {value: '1', label: '是'}],
      updatedRevisionList: [{value: 'N', label: '否'}, {value: 'Y', label: '是'}],
      flag: false,
      loadText: '',
    };
  },
  created() {
    this.getMaterialList();
    this.getLineList();
    this.getProductList();
    this.getRoutingList();
    this.getList();

    this.getDicts("order_type").then((response) => {
      this.orderOptions = response.data;
    });
  },
  methods: {
    submitList() {
      this.loadingVerify = true
      updatePoVersion(this.entityRevisionList).then((res) => {
        this.msgSuccess("上传成功");
        this.loadingVerify = false
        this.openVerify = false
      }).catch(() => {
        this.msgError("上传失败");
        this.loadingVerify = false
        this.openVerify = false

      })
    },
    updatedFormatter(val) {
      if (val.existUpdated == "Y") {
        return "是";
      } else {
        return "否";
      }
    },
    revisionFormatter(val) {
      if (val.specialRevision == "1") {
        return "是";
      } else {
        return "否";
      }
    },
    modeFormatter(val) {
      switch (val.modeProcduction) {
        case "0":
          return "烧录软件";
        case "1":
          return "加载软件";
        default:
          return "";
      }
    },
    /** 提交按钮 */
    submitVerifyForm() {
      this.$refs["verifyForm"].validate((valid) => {
        if (valid) {
          this.entityRevisionList[this.verifyForm.id] = this.verifyForm
          // console.log(this.entityRevisionList);
          this.openUpdate = false;
        }
      });
    },
    cancelVerify() {
      this.openUpdate = false;
    },
    updateVerify(val) {
      this.openUpdate = true;
      this.verifyForm = val;
    },
    handleStatus(row, column, cellValue, index) {
      switch (cellValue) {
        case "1":
          return "新建";
        case "2":
          return "已齐套";
        case "3":
          return "已下发";
        case "4":
          return "已完成";
      }
    },

    /** 查询工单信息列表 */
    getList() {
      this.loading = true;
      // this.queryParams.orderByColumn = "orderState";
      // this.queryParams.isAsc = "desc";
      listOrder(this.queryParams).then((response) => {
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 工单状态字典翻译
    orderStateModeFormat(row, column) {
      return this.selectDictLabel(this.orderOptions, row.orderState);
    },
    // 查询物料下拉
    getMaterialList() {
      listMaterial({}).then((response) => {
        this.materialOptions = response;
      });
    },
    // 查询产线下拉
    getLineList() {
      getTree(3).then((response) => {
        this.lineOptions = response.data;
      });
    },
    // 查询产品下拉
    getProductList() {
      listProduct({}).then((response) => {
        this.productOptions = response.data;
      });
    },
    // 查询工艺路线下拉
    getRoutingList() {
      listOperations({}).then((response) => {
        this.routingOptions = response;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {};
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 点击版本校验
    handleVerify(val) {
      if (val.orderState == '3' || val.orderState == '4') {
        this.flag = true
      } else {
        this.flag = false
      }
      this.openVerify = true;
      this.verifyPo = val.taskTon;
      this.verifyOrderId = val.orderId;
      this.getVersionList();

    },
    getVersionList() {
      this.loadingVerify = true;

      getPoVersion({taskTon: this.verifyPo,})
        .then((res) => {
          this.entityRevisionList = res.data;
          this.loadingVerify = false;
        })
        .catch(() => {
          this.loadingVerify = false;
        });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // table弹框
    showDictData(row) {
      this.orderId = row.orderId;
      this.stepsVisible = true;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加工单信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const orderId = row.orderId || this.ids;
      getOrder(orderId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工单信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.orderId != null) {
            updateOrder(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addOrder(this.form).then((response) => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orderIds = row.orderId || this.ids;
      this.$confirm(
        '是否确认删除工单信息编号为"' + orderIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delOrder(orderIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(function () {
        });
    },
    // 齐套验证
    handleQT(row) {
      const orderIds = row.orderId || 0;
      this.$confirm(
        '是否确认齐套信息编号为"' + orderIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.loading = true
          this.loadText = '齐套验证中'

          return qtOrder(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("齐套成功");
        })
        .catch(() => {
          this.loading = false
        });
    },
    /** 下发按钮操作 */
    handleTransmit(row) {
      const orderIds = row.orderId || 0;
      this.$confirm(
        '是否确认下发工单信息编号为"' + orderIds + '"的数据项且版本校验已完成?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(() => {
          this.loading = true
          this.loadText = '下发工单中'

          return transmitOrder(row);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("下发成功");
        })
        .catch(() => {
          this.loading = false
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有工单信息数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportOrder(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        })
        .catch(function () {
        });
    },
  },
};
</script>
